.class public Lcom/qiniu/io/IO;
.super Ljava/lang/Object;
.source "IO.java"


# static fields
.field public static UNDEFINED_KEY:Ljava/lang/String;

.field private static mClient:Lcom/qiniu/auth/Client;

.field private static mUptoken:Ljava/lang/String;


# direct methods
.method static constructor <clinit>()V
    .registers 1

    .prologue
    .line 21
    const/4 v0, 0x0

    sput-object v0, Lcom/qiniu/io/IO;->UNDEFINED_KEY:Ljava/lang/String;

    return-void
.end method

.method public constructor <init>(Lcom/qiniu/auth/Client;Ljava/lang/String;)V
    .registers 3
    .param p1, "client"    # Lcom/qiniu/auth/Client;
    .param p2, "uptoken"    # Ljava/lang/String;

    .prologue
    .line 24
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 25
    sput-object p1, Lcom/qiniu/io/IO;->mClient:Lcom/qiniu/auth/Client;

    .line 26
    sput-object p2, Lcom/qiniu/io/IO;->mUptoken:Ljava/lang/String;

    .line 27
    return-void
.end method

.method public static convertFileUri(Landroid/content/Context;Landroid/net/Uri;)Landroid/net/Uri;
    .registers 11
    .param p0, "mContext"    # Landroid/content/Context;
    .param p1, "uri"    # Landroid/net/Uri;

    .prologue
    const/4 v8, 0x0

    const/4 v3, 0x0

    .line 120
    if-eqz p1, :cond_44

    const-string v0, "content"

    invoke-virtual {p1}, Landroid/net/Uri;->getScheme()Ljava/lang/String;

    move-result-object v1

    invoke-virtual {v0, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v0

    if-eqz v0, :cond_44

    .line 121
    invoke-virtual {p0}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

    move-result-object v0

    const/4 v1, 0x1

    new-array v2, v1, [Ljava/lang/String;

    const-string v1, "_data"

    aput-object v1, v2, v8

    move-object v1, p1

    move-object v4, v3

    move-object v5, v3

    invoke-virtual/range {v0 .. v5}, Landroid/content/ContentResolver;->query(Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v6

    .line 122
    .local v6, "cursor":Landroid/database/Cursor;
    invoke-interface {v6}, Landroid/database/Cursor;->moveToFirst()Z

    .line 123
    invoke-interface {v6, v8}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object v7

    .line 124
    .local v7, "filePath":Ljava/lang/String;
    invoke-interface {v6}, Landroid/database/Cursor;->close()V

    .line 128
    .end local v6    # "cursor":Landroid/database/Cursor;
    :goto_2c
    new-instance v0, Ljava/lang/StringBuilder;

    invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V

    const-string v1, "file://"

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    invoke-static {v0}, Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;

    move-result-object v0

    return-object v0

    .line 126
    .end local v7    # "filePath":Ljava/lang/String;
    :cond_44
    invoke-virtual {p1}, Landroid/net/Uri;->getPath()Ljava/lang/String;

    move-result-object v7

    .restart local v7    # "filePath":Ljava/lang/String;
    goto :goto_2c
.end method

.method private static defaultClient()Lcom/qiniu/auth/Client;
    .registers 1

    .prologue
    .line 30
    sget-object v0, Lcom/qiniu/io/IO;->mClient:Lcom/qiniu/auth/Client;

    if-nez v0, :cond_a

    .line 31
    invoke-static {}, Lcom/qiniu/auth/Client;->defaultClient()Lcom/qiniu/auth/Client;

    move-result-object v0

    sput-object v0, Lcom/qiniu/io/IO;->mClient:Lcom/qiniu/auth/Client;

    .line 33
    :cond_a
    sget-object v0, Lcom/qiniu/io/IO;->mClient:Lcom/qiniu/auth/Client;

    return-object v0
.end method

.method public static put(Ljava/lang/String;Ljava/lang/String;Lcom/qiniu/utils/InputStreamAt;Lcom/qiniu/io/PutExtra;Lcom/qiniu/auth/JSONObjectRet;)V
    .registers 7
    .param p0, "uptoken"    # Ljava/lang/String;
    .param p1, "key"    # Ljava/lang/String;
    .param p2, "input"    # Lcom/qiniu/utils/InputStreamAt;
    .param p3, "extra"    # Lcom/qiniu/io/PutExtra;
    .param p4, "callback"    # Lcom/qiniu/auth/JSONObjectRet;

    .prologue
    .line 132
    new-instance v0, Lcom/qiniu/io/IO;

    invoke-static {}, Lcom/qiniu/io/IO;->defaultClient()Lcom/qiniu/auth/Client;

    move-result-object v1

    invoke-direct {v0, v1, p0}, Lcom/qiniu/io/IO;-><init>(Lcom/qiniu/auth/Client;Ljava/lang/String;)V

    invoke-virtual {v0, p1, p2, p3, p4}, Lcom/qiniu/io/IO;->put(Ljava/lang/String;Lcom/qiniu/utils/InputStreamAt;Lcom/qiniu/io/PutExtra;Lcom/qiniu/auth/JSONObjectRet;)V

    .line 133
    return-void
.end method

.method public static putFile(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Landroid/net/Uri;Lcom/qiniu/io/PutExtra;Lcom/qiniu/auth/JSONObjectRet;)V
    .registers 12
    .param p0, "mContext"    # Landroid/content/Context;
    .param p1, "uptoken"    # Ljava/lang/String;
    .param p2, "key"    # Ljava/lang/String;
    .param p3, "uri"    # Landroid/net/Uri;
    .param p4, "extra"    # Lcom/qiniu/io/PutExtra;
    .param p5, "callback"    # Lcom/qiniu/auth/JSONObjectRet;

    .prologue
    .line 136
    new-instance v0, Lcom/qiniu/io/IO;

    invoke-static {}, Lcom/qiniu/io/IO;->defaultClient()Lcom/qiniu/auth/Client;

    move-result-object v1

    invoke-direct {v0, v1, p1}, Lcom/qiniu/io/IO;-><init>(Lcom/qiniu/auth/Client;Ljava/lang/String;)V

    move-object v1, p0

    move-object v2, p2

    move-object v3, p3

    move-object v4, p4

    move-object v5, p5

    invoke-virtual/range {v0 .. v5}, Lcom/qiniu/io/IO;->putFile(Landroid/content/Context;Ljava/lang/String;Landroid/net/Uri;Lcom/qiniu/io/PutExtra;Lcom/qiniu/auth/JSONObjectRet;)V

    .line 137
    return-void
.end method

.method public static putFile(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;Lcom/qiniu/io/PutExtra;Lcom/qiniu/auth/JSONObjectRet;)V
    .registers 7
    .param p0, "uptoken"    # Ljava/lang/String;
    .param p1, "key"    # Ljava/lang/String;
    .param p2, "file"    # Ljava/io/File;
    .param p3, "extra"    # Lcom/qiniu/io/PutExtra;
    .param p4, "callback"    # Lcom/qiniu/auth/JSONObjectRet;

    .prologue
    .line 139
    new-instance v0, Lcom/qiniu/io/IO;

    invoke-static {}, Lcom/qiniu/io/IO;->defaultClient()Lcom/qiniu/auth/Client;

    move-result-object v1

    invoke-direct {v0, v1, p0}, Lcom/qiniu/io/IO;-><init>(Lcom/qiniu/auth/Client;Ljava/lang/String;)V

    invoke-virtual {v0, p1, p2, p3, p4}, Lcom/qiniu/io/IO;->putFile(Ljava/lang/String;Ljava/io/File;Lcom/qiniu/io/PutExtra;Lcom/qiniu/auth/JSONObjectRet;)V

    .line 140
    return-void
.end method


# virtual methods
.method public put(Ljava/lang/String;Lcom/qiniu/utils/InputStreamAt;Lcom/qiniu/io/PutExtra;Lcom/qiniu/auth/JSONObjectRet;)V
    .registers 13
    .param p1, "key"    # Ljava/lang/String;
    .param p2, "isa"    # Lcom/qiniu/utils/InputStreamAt;
    .param p3, "extra"    # Lcom/qiniu/io/PutExtra;
    .param p4, "ret"    # Lcom/qiniu/auth/JSONObjectRet;

    .prologue
    .line 45
    new-instance v3, Lcom/qiniu/utils/MultipartEntity;

    invoke-direct {v3}, Lcom/qiniu/utils/MultipartEntity;-><init>()V

    .line 46
    .local v3, "m":Lcom/qiniu/utils/MultipartEntity;
    if-eqz p1, :cond_c

    const-string v4, "key"

    invoke-virtual {v3, v4, p1}, Lcom/qiniu/utils/MultipartEntity;->addField(Ljava/lang/String;Ljava/lang/String;)V

    .line 47
    :cond_c
    iget v4, p3, Lcom/qiniu/io/PutExtra;->checkCrc:I

    const/4 v5, 0x1

    if-ne v4, v5, :cond_17

    invoke-virtual {p2}, Lcom/qiniu/utils/InputStreamAt;->crc32()J

    move-result-wide v4

    iput-wide v4, p3, Lcom/qiniu/io/PutExtra;->crc32:J

    .line 48
    :cond_17
    iget v4, p3, Lcom/qiniu/io/PutExtra;->checkCrc:I

    if-eqz v4, :cond_35

    const-string v4, "crc32"

    new-instance v5, Ljava/lang/StringBuilder;

    invoke-direct {v5}, Ljava/lang/StringBuilder;-><init>()V

    iget-wide v6, p3, Lcom/qiniu/io/PutExtra;->crc32:J

    invoke-virtual {v5, v6, v7}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    move-result-object v5

    const-string v6, ""

    invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v5

    invoke-virtual {v5}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v3, v4, v5}, Lcom/qiniu/utils/MultipartEntity;->addField(Ljava/lang/String;Ljava/lang/String;)V

    .line 49
    :cond_35
    iget-object v4, p3, Lcom/qiniu/io/PutExtra;->params:Ljava/util/HashMap;

    invoke-virtual {v4}, Ljava/util/HashMap;->entrySet()Ljava/util/Set;

    move-result-object v4

    invoke-interface {v4}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v6

    :goto_3f
    invoke-interface {v6}, Ljava/util/Iterator;->hasNext()Z

    move-result v4

    if-eqz v4, :cond_5b

    invoke-interface {v6}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Ljava/util/Map$Entry;

    .local v2, "i":Ljava/util/Map$Entry;, "Ljava/util/Map$Entry<Ljava/lang/String;Ljava/lang/String;>;"
    invoke-interface {v2}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v4

    check-cast v4, Ljava/lang/String;

    invoke-interface {v2}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v5

    check-cast v5, Ljava/lang/String;

    invoke-virtual {v3, v4, v5}, Lcom/qiniu/utils/MultipartEntity;->addField(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_3f

    .line 51
    .end local v2    # "i":Ljava/util/Map$Entry;, "Ljava/util/Map$Entry<Ljava/lang/String;Ljava/lang/String;>;"
    :cond_5b
    const-string v4, "token"

    sget-object v5, Lcom/qiniu/io/IO;->mUptoken:Ljava/lang/String;

    invoke-virtual {v3, v4, v5}, Lcom/qiniu/utils/MultipartEntity;->addField(Ljava/lang/String;Ljava/lang/String;)V

    .line 52
    const-string v4, "file"

    iget-object v5, p3, Lcom/qiniu/io/PutExtra;->mimeType:Ljava/lang/String;

    if-nez p1, :cond_6a

    const-string p1, "?"

    .end local p1    # "key":Ljava/lang/String;
    :cond_6a
    invoke-virtual {v3, v4, v5, p1, p2}, Lcom/qiniu/utils/MultipartEntity;->addFile(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/qiniu/utils/InputStreamAt;)V

    .line 54
    invoke-static {}, Lcom/qiniu/io/IO;->defaultClient()Lcom/qiniu/auth/Client;

    move-result-object v0

    .line 55
    .local v0, "client":Lcom/qiniu/auth/Client;
    invoke-virtual {v0}, Lcom/qiniu/auth/Client;->makeClientExecutor()Lcom/qiniu/auth/Client$ClientExecutor;

    move-result-object v1

    .line 56
    .local v1, "executor":Lcom/qiniu/auth/Client$ClientExecutor;
    new-instance v4, Lcom/qiniu/io/IO$1;

    invoke-direct {v4, p0, v1}, Lcom/qiniu/io/IO$1;-><init>(Lcom/qiniu/io/IO;Lcom/qiniu/auth/Client$ClientExecutor;)V

    invoke-virtual {v3, v4}, Lcom/qiniu/utils/MultipartEntity;->setProcessNotify(Lcom/qiniu/utils/IOnProcess;)V

    .line 62
    const-string v4, "http://up.qiniu.com"

    invoke-virtual {v0, v1, v4, v3, p4}, Lcom/qiniu/auth/Client;->call(Lcom/qiniu/auth/Client$ClientExecutor;Ljava/lang/String;Lorg/apache/http/HttpEntity;Lcom/qiniu/auth/CallRet;)Lcom/qiniu/auth/Client$ClientExecutor;

    .line 63
    return-void
.end method

.method public putAndClose(Ljava/lang/String;Lcom/qiniu/utils/InputStreamAt;Lcom/qiniu/io/PutExtra;Lcom/qiniu/auth/JSONObjectRet;)V
    .registers 6
    .param p1, "key"    # Ljava/lang/String;
    .param p2, "input"    # Lcom/qiniu/utils/InputStreamAt;
    .param p3, "extra"    # Lcom/qiniu/io/PutExtra;
    .param p4, "ret"    # Lcom/qiniu/auth/JSONObjectRet;

    .prologue
    .line 93
    new-instance v0, Lcom/qiniu/io/IO$2;

    invoke-direct {v0, p0, p2, p4}, Lcom/qiniu/io/IO$2;-><init>(Lcom/qiniu/io/IO;Lcom/qiniu/utils/InputStreamAt;Lcom/qiniu/auth/JSONObjectRet;)V

    invoke-virtual {p0, p1, p2, p3, v0}, Lcom/qiniu/io/IO;->put(Ljava/lang/String;Lcom/qiniu/utils/InputStreamAt;Lcom/qiniu/io/PutExtra;Lcom/qiniu/auth/JSONObjectRet;)V

    .line 116
    return-void
.end method

.method public putFile(Landroid/content/Context;Ljava/lang/String;Landroid/net/Uri;Lcom/qiniu/io/PutExtra;Lcom/qiniu/auth/JSONObjectRet;)V
    .registers 11
    .param p1, "mContext"    # Landroid/content/Context;
    .param p2, "key"    # Ljava/lang/String;
    .param p3, "uri"    # Landroid/net/Uri;
    .param p4, "extra"    # Lcom/qiniu/io/PutExtra;
    .param p5, "ret"    # Lcom/qiniu/auth/JSONObjectRet;

    .prologue
    .line 75
    invoke-virtual {p3}, Landroid/net/Uri;->toString()Ljava/lang/String;

    move-result-object v2

    const-string v3, "file"

    invoke-virtual {v2, v3}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z

    move-result v2

    if-nez v2, :cond_10

    invoke-static {p1, p3}, Lcom/qiniu/io/IO;->convertFileUri(Landroid/content/Context;Landroid/net/Uri;)Landroid/net/Uri;

    move-result-object p3

    .line 77
    :cond_10
    :try_start_10
    new-instance v1, Ljava/io/File;

    new-instance v2, Ljava/net/URI;

    invoke-virtual {p3}, Landroid/net/Uri;->toString()Ljava/lang/String;

    move-result-object v3

    invoke-direct {v2, v3}, Ljava/net/URI;-><init>(Ljava/lang/String;)V

    invoke-direct {v1, v2}, Ljava/io/File;-><init>(Ljava/net/URI;)V

    .line 78
    .local v1, "file":Ljava/io/File;
    invoke-virtual {v1}, Ljava/io/File;->exists()Z

    move-result v2

    if-eqz v2, :cond_2c

    .line 79
    invoke-static {v1}, Lcom/qiniu/utils/InputStreamAt;->fromFile(Ljava/io/File;)Lcom/qiniu/utils/InputStreamAt;

    move-result-object v2

    invoke-virtual {p0, p2, v2, p4, p5}, Lcom/qiniu/io/IO;->putAndClose(Ljava/lang/String;Lcom/qiniu/utils/InputStreamAt;Lcom/qiniu/io/PutExtra;Lcom/qiniu/auth/JSONObjectRet;)V

    .line 87
    .end local v1    # "file":Ljava/io/File;
    :goto_2b
    return-void

    .line 82
    .restart local v1    # "file":Ljava/io/File;
    :cond_2c
    new-instance v2, Ljava/lang/Exception;

    new-instance v3, Ljava/lang/StringBuilder;

    invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V

    const-string v4, "file not exist: "

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {p3}, Landroid/net/Uri;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v3

    invoke-direct {v2, v3}, Ljava/lang/Exception;-><init>(Ljava/lang/String;)V

    invoke-virtual {p5, v2}, Lcom/qiniu/auth/JSONObjectRet;->onFailure(Ljava/lang/Exception;)V
    :try_end_4b
    .catch Ljava/net/URISyntaxException; {:try_start_10 .. :try_end_4b} :catch_4c

    goto :goto_2b

    .line 83
    .end local v1    # "file":Ljava/io/File;
    :catch_4c
    move-exception v0

    .line 84
    .local v0, "e":Ljava/net/URISyntaxException;
    invoke-virtual {v0}, Ljava/net/URISyntaxException;->printStackTrace()V

    .line 85
    invoke-virtual {p5, v0}, Lcom/qiniu/auth/JSONObjectRet;->onFailure(Ljava/lang/Exception;)V

    goto :goto_2b
.end method

.method public putFile(Ljava/lang/String;Ljava/io/File;Lcom/qiniu/io/PutExtra;Lcom/qiniu/auth/JSONObjectRet;)V
    .registers 6
    .param p1, "key"    # Ljava/lang/String;
    .param p2, "file"    # Ljava/io/File;
    .param p3, "extra"    # Lcom/qiniu/io/PutExtra;
    .param p4, "callback"    # Lcom/qiniu/auth/JSONObjectRet;

    .prologue
    .line 89
    invoke-static {p2}, Lcom/qiniu/utils/InputStreamAt;->fromFile(Ljava/io/File;)Lcom/qiniu/utils/InputStreamAt;

    move-result-object v0

    invoke-virtual {p0, p1, v0, p3, p4}, Lcom/qiniu/io/IO;->putAndClose(Ljava/lang/String;Lcom/qiniu/utils/InputStreamAt;Lcom/qiniu/io/PutExtra;Lcom/qiniu/auth/JSONObjectRet;)V

    .line 90
    return-void
.end method
